package org.haier.aws.utils;

import com.amazonaws.services.iot.AWSIot;
import com.amazonaws.services.iot.AWSIotClientBuilder;
import org.haier.aws.config.AwsConfig;

/**
 * Iot Core核心工具类
 * @author: SongKun
 * @date: 2021/5/13
 */
public class AWSIotUtils {

    private volatile static AWSIot awsIot = null;

    public static AWSIot getAwsIot() {
        if (awsIot == null) {
            synchronized (AWSIotUtils.class) {
                if (awsIot == null) {
                    awsIot = AWSIotClientBuilder.standard()
                            .withRegion(AwsConfig.REGION)
                            //.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(AwsConfig.ENDPOINT, AwsConfig.REGION))
                            .build();

                }
            }
        }
        return awsIot;
    }

    public static String getCertificateARN(String accountId, String certificateId) {
        return "arn:aws:iot:" +
                AwsConfig.REGION + ":" +
                accountId + ":" +
                "cert/" + certificateId;
    }

}
